package cm.android.mytodoit;

import android.R;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import cm.android.mytodoit.view.BuyListView;
import cm.android.mytodoit.view.GenerateBuyView;
import cm.android.mytodoit.view.GenerateTodoView;
import cm.android.mytodoit.view.TodoListView;

public class MyTodoActivity extends TabActivity {

	TabHost tabHost = null;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);		

		tabHost = this.getTabHost();
		
		TabSpec todo = tabHost.newTabSpec("todo");
		todo.setIndicator("Todo",getResources().getDrawable( R.drawable.ic_menu_agenda));
		todo.setContent(new Intent(this, TodoListView.class));

		TabSpec buy = tabHost.newTabSpec("buy");
		buy.setIndicator("Buy", getResources().getDrawable(R.drawable.ic_menu_share));
		buy.setContent(new Intent(this, BuyListView.class));		

		tabHost.addTab(todo);
		tabHost.addTab(buy);
	}
	
	@Override
	protected void onPause() {
		Intent  intent = new  Intent("UPADTE_WIDGET");
		sendBroadcast(intent);
		super.onPause();
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(cm.android.mytodoit.R.menu.tabmenu, menu);
		return super.onCreateOptionsMenu(menu);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case cm.android.mytodoit.R.id.opt_addTodo:
			
			startActivity(new Intent(this, GenerateTodoView.class));

			break;
		case cm.android.mytodoit.R.id.opt_addBuy:
			
			startActivity(new Intent(this, GenerateBuyView.class));
			break;
		}
		return super.onOptionsItemSelected(item);
	}
}